<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of masterrekening
 *
 * @author miyzan
 */
class biayasiswa extends MY_Controller{
    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model("biayasiswa_model","datamodel");
    }
    
    public function get_rows() {

        $page   =   ($this->input->post('page', TRUE) ? $this->input->post('page', TRUE) : 1);
        $start = isset($_POST['start']) ? $this->db->escape_str($this->input->post('start', TRUE)) : 0;
        $limit = isset($_POST['limit']) ? $this->db->escape_str($this->input->post('limit', TRUE)) : $this->config->item("length_records");
        $search = isset($_POST['query']) ? $this->db->escape_str($this->input->post('query', TRUE)) : '';

        $result = $this->datamodel->get_rows($search, $start, $limit);
        echo $result;
    }
    public function get_rows_all() {

        $result = $this->datamodel->get_rows_all();
        echo $result;
    }
    
    public function get_rows_combo() {

        $result = $this->datamodel->get_rows_combo();
        echo $result;
    }
    
    public function get_rows_entry() {
        $nis = isset($_POST['nis']) ? $this->db->escape_str($this->input->post('nis', TRUE)) : '';
        $th = isset($_POST['idth']) ? $this->db->escape_str($this->input->post('idth', TRUE)) : '';
        $result = $this->datamodel->get_rows_entry($nis,$th);
        echo $result;
    }
    
    
    public function update_rows()
    {
        $opt = isset($_POST['cmd']) ? $this->db->escape_str($this->input->post('cmd', TRUE)) : '';
        $nis=isset($_POST['nis']) ? $this->db->escape_str($this->input->post('nis', TRUE)) : '';
        $id_th_ajaran=isset($_POST['id_th_ajaran']) ? $this->db->escape_str($this->input->post('id_th_ajaran', TRUE)) : '';
        $data = isset($_POST['postdata']) ? json_decode($this->input->post('postdata', TRUE)): array(); 
        
        $kd_biaya=isset($_POST['kd_biaya']) ? $this->db->escape_str($this->input->post('kd_biaya', TRUE)) : '';
        $biaya_dasar=isset($_POST['mbiaya_dasar']) ? $this->db->escape_str($this->input->post('mbiaya_dasar', TRUE)) : 0;
        $biaya_dikenakan=isset($_POST['mbiaya_dikenakan']) ? $this->db->escape_str($this->input->post('mbiaya_dikenakan', TRUE)) : 0;
        $id=isset($_POST['id']) ? $this->db->escape_str($this->input->post('id', TRUE)) : NULL;
        $id_user=$this->session->userdata('username');
        
        $result='';
        $spname='sp_biayasiswa';
        if($opt=='insert'){
            $id=NULL;
            
            foreach ($data as $v) {
                $kd_biaya=$v->kd_biaya;
                $biaya_dasar=$v->biaya_dasar;
                $biaya_dikenakan=$v->biaya_dikenakan;
                $param=array($opt,$id,$nis,$id_th_ajaran,$kd_biaya,$biaya_dasar,$biaya_dikenakan,$id_user);        
                $result = $this->datamodel->SP_execData($spname, $param, true);
            }
        }else{
            $param=array($opt,$id,$nis,$id_th_ajaran,$kd_biaya,$biaya_dasar,$biaya_dikenakan,$id_user);        
            $result = $this->datamodel->SP_execData($spname, $param, true);
        }
        
        
        
        echo $result;        
    }
    
    public function delete_row()
    {
        $opt = isset($_POST['cmd']) ? $this->db->escape_str($this->input->post('cmd', TRUE)) : '';
        $data = isset($_POST['postdata']) ? json_decode($this->input->post('postdata', TRUE)): array(); 
        $id=$data->id;
        $nis=$data->nis;
        $id_th_ajaran=$data->id_th_ajaran;
        $kd_biaya=$data->kd_biaya;
        $biaya_dasar=$data->biaya_dasar;
        $biaya_dikenakan=$data->biaya_dikenakan;
        $tgl_entri=$data->tgl_entri;
        $id_user=$data->id_user;

        $spname='sp_biayasiswa';
        $param=array($opt,$id,$nis,$id_th_ajaran,$kd_biaya,$biaya_dasar,$biaya_dikenakan,$id_user);        
        $result = $this->datamodel->SP_execData($spname, $param, true);        
        echo $result;
        
    }
    
    
}

?>
